package com.woniuxy.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.woniuxy.system.entity.AssessmentType;
import com.woniuxy.system.entity.DataRecord;
import com.woniuxy.system.mapper.AssessmentTypeMapper;
import com.woniuxy.system.mapper.DataRecordMapper;
import com.woniuxy.system.service.AssessmentTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * <p>
 * 考核种类	 服务实现类
 * </p>
 *
 * @author woniuxy
 * @since 2022-06-01
 */
@Service
@Transactional
public class AssessmentTypeServiceImpl extends ServiceImpl<AssessmentTypeMapper, AssessmentType> implements AssessmentTypeService {

    @Autowired
    DataRecordMapper dataRecordMapper;
    @Autowired
    AssessmentTypeMapper assessmentTypeMapper;

    @Override
    public Page<AssessmentType> getAllAssessmentType(IPage<AssessmentType> page, Wrapper<AssessmentType> wrapper) {
        return assessmentTypeMapper.getAllAssessmentType(page,wrapper);
    }

    @Override
    public boolean addAssessmentType(AssessmentType assessmentType,String userid) {
        DataRecord dataRecord = new DataRecord();
        dataRecord.setCreateTime(new Date());
        dataRecord.setInfo("新建考核种类");
        dataRecord.setUserId(Long.valueOf(userid));
        int insert = dataRecordMapper.insert(dataRecord);
        System.out.println("datarecordeId="+dataRecord.getId());
        assessmentType.setRecordId(dataRecord.getId());
        int insert1 = assessmentTypeMapper.insert(assessmentType);
        if(insert==1&&insert1==1){
            return  true;
        }
        return false;
    }
}
